package pers.flowerinsnow.minecraft.forge.shiftability.listener

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.InputEvent
import pers.flowerinsnow.minecraft.forge.shiftability.ShiftAbility
import pers.flowerinsnow.minecraft.forge.shiftability.manager.ISAConfigManager
import pers.flowerinsnow.minecraft.forge.shiftability.manager.KeyManager

class KeyListener {
    @SubscribeEvent
    fun onKeyInput(e : InputEvent.KeyInputEvent) {
        if (KeyManager.TOGGLE.isPressed) {
            val old = ISAConfigManager.ConfigEntry.GENERAL_ENABLE.get().boolean
            if (old) {
                TickListener.next = -1L;
                ShiftAbility.addChat("command.shiftability.disable")
            } else {
                TickListener.next = System.currentTimeMillis() + ISAConfigManager.ConfigEntry.GENERAL_PERIOD.get().int
                ShiftAbility.addChat("command.shiftability.enable")
            }
            ISAConfigManager.ConfigEntry.GENERAL_ENABLE.get().set(!old)
            ShiftAbility.configManager.save()
        }
    }
}